//
//  AwemeCollectionCell.m
//  Douyin
//
//  Created by Qiao Shi on 2018/7/30.
//  Copyright © 2018年 Qiao Shi. All rights reserved.
//

#import "AwemeCollectionCell.h"
//#import "Constants.h"
#import "Masonry.h"
#import "NSString+Extension.h"
@implementation AwemeCollectionCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self){
        self.clipsToBounds = YES;
        _imageView = [[UIImageView alloc] init];
        _imageView.backgroundColor = ColorThemeGray;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_imageView];
        
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)ColorClear.CGColor, (__bridge id)ColorBlackAlpha20.CGColor, (__bridge id)ColorBlackAlpha60.CGColor];
        gradientLayer.locations = @[@0.3, @0.6, @1.0];
        gradientLayer.startPoint = CGPointMake(0.0f, 0.0f);
        gradientLayer.endPoint = CGPointMake(0.0f, 1.0f);
        gradientLayer.frame = CGRectMake(0, self.frame.size.height - 100, self.frame.size.width, 100);
        [_imageView.layer addSublayer:gradientLayer];
        
        _favoriteNum = [[UIButton alloc] init];
        [_favoriteNum setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//        [_favoriteNum setTitleEdgeInsets:UIEdgeInsetsMake(0, 2, 0, 0)];
        [_favoriteNum setTitle:@"0" forState:UIControlStateNormal];
        [_favoriteNum setTitleColor:ColorWhite forState:UIControlStateNormal];
        _favoriteNum.titleLabel.font = SmallFont;
        [_favoriteNum setImage:[UIImage imageNamed:@"ic_my_themecollect"] forState:UIControlStateNormal];
//        [_favoriteNum setImageEdgeInsets:UIEdgeInsetsMake(0, -2, 0, 0)];
        
        
        _broserNum = [[UIButton alloc] init];
        [_broserNum setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//        [_broserNum setTitleEdgeInsets:UIEdgeInsetsMake(0, 2, 0, 0)];
        [_broserNum setTitle:@"0" forState:UIControlStateNormal];
        [_broserNum setTitleColor:ColorWhite forState:UIControlStateNormal];
        _broserNum.titleLabel.font = SmallFont;
        [_broserNum setImage:[UIImage imageNamed:@"ic_my_themewatch"] forState:UIControlStateNormal];
//        [_broserNum setImageEdgeInsets:UIEdgeInsetsMake(0, -2, 0, 0)];
        
        [self addSubview:_broserNum];
        [self addSubview:_favoriteNum];
    }
    return self;
}

-(void)setHighlighted:(BOOL)highlighted {
    [super setHighlighted:NO];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _imageView.frame = self.bounds;
    [_favoriteNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.equalTo(self).offset(-10);
        
    }];
    
    [_broserNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.favoriteNum.mas_right).offset(5);
        make.centerY.equalTo(self.favoriteNum.mas_centerY);
    }];
}

- (void)prepareForReuse {
    [super prepareForReuse];
//    [self.imageView setImage:nil];
}

- (void)initData:(MHAwemeModel *)aweme {
    __weak __typeof(self) wself = self;
    
    if (aweme.vedioObj) {
        [self.imageView yy_setImageWithURL:aweme.vedioObj.coverURL placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
    }else
    {
        if (aweme.attm) {
            [self.imageView yy_setImageWithURL:[NSURL URLWithString:aweme.attm.fullPath] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
        }
        
    }
   
    [self.favoriteNum setTitle: [NSString stringWithFormat:@" %@",[NSString formatCount:aweme.likeCount]] forState:UIControlStateNormal];
    
    [self.broserNum setTitle:[NSString stringWithFormat:@" %@",[NSString formatCount:aweme.viewCount]] forState:UIControlStateNormal];
//    [self.broserNum sizeToFit];
//    [self.favoriteNum sizeToFit];
//    self.broserNum.width =  self.broserNum.width + 4;
//    self.favoriteNum.width = self.favoriteNum.width + 4;
}

@end
